package com.zh.jetpackmvvm.network.interceptor

import okhttp3.Interceptor
import okhttp3.Response

/**
 * @author :zhouh
 * email：zhouhe@sixarm.cn
 * time：2020-06-03
 * company：山东六臂网络科技有限公司
 * desc：头部参数拦截器，传入heads
 */
class HeadInterceptor(private val headers: Map<String, String>? = null) : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        if (headers != null && headers.isNotEmpty()) {
            val keys = headers.keys
            for (headerKey in keys) {
                headers[headerKey]?.let {
                    builder.addHeader(headerKey, it).build()
                }
            }
        }
        //请求信息
        return chain.proceed(builder.build())
    }
}